package net.maku.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import net.maku.framework.common.page.PageResult;
import net.maku.framework.common.service.impl.BaseServiceImpl;
import net.maku.system.convert.OperationLogConvert;
import net.maku.system.dao.OperationLogDao;
import net.maku.system.entity.OperationLogEntity;
import net.maku.system.query.OperationLogQuery;
import net.maku.system.service.OperationLogService;
import net.maku.system.vo.OperationLogVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 皂搓日志
 *
 * @author yebing 
 * @since 1.0.0 2023-07-29
 */
@Service
@AllArgsConstructor
public class OperationLogServiceImpl extends BaseServiceImpl<OperationLogDao, OperationLogEntity> implements OperationLogService {

    @Override
    public PageResult<OperationLogVO> page(OperationLogQuery query) {
        IPage<OperationLogEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));

        return new PageResult<>(OperationLogConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }

    private QueryWrapper<OperationLogEntity> getWrapper(OperationLogQuery query){
        QueryWrapper<OperationLogEntity> wrapper = new QueryWrapper<>();

        return wrapper;
    }

    @Override
    public void save(OperationLogVO vo) {
        OperationLogEntity entity = OperationLogConvert.INSTANCE.convert(vo);

        baseMapper.insert(entity);
    }

    @Override
    public void update(OperationLogVO vo) {
        OperationLogEntity entity = OperationLogConvert.INSTANCE.convert(vo);

        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}